using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;

// TODO: replace these with the processor input and output types.
using TInput = System.String;
using TOutput = CoolEngine.Engine.Scripting.PythonSourceFile;
using System.ComponentModel;
using System.IO;
using IronPython.Compiler.Ast;
using IronPython.Compiler;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using IronPython.Hosting;

namespace ContentExtensions
{
    /// <summary>
    /// This class will be instantiated by the XNA Framework Content Pipeline
    /// to apply custom processing to content data, converting an object of
    /// type TInput to TOutput. The input and output types may be the same if
    /// the processor wishes to alter data without changing its type.
    /// </summary>
    [ContentProcessor(DisplayName = "PythonSourceProcessor")]
    public class PythonSourceProcessor : ContentProcessor<TInput, TOutput>
    {
        [Description("What module to place this source file in.")]
        [DisplayName("Module name")]
        [DefaultValue("")]
        public string ModuleName { get; set; }
        public override TOutput Process(TInput input, ContentProcessorContext context)
        {
            if (string.IsNullOrEmpty(ModuleName))
            {                
                ModuleName = Path.GetFileNameWithoutExtension(context.OutputPath);
                context.Logger.LogWarning(null, new ContentIdentity(), context.OutputPath + " wasn't given a module name; using" + Path.GetFileNameWithoutExtension(context.OutputPath));
            }

            
            //if (parser.ErrorCode != 0)
            //{
            //    throw new CompilationFailedException("Compilation failed with error code " + parser.ErrorCode);
            //}
            return new TOutput() { Module = ModuleName, Text = input };
        }
    }
}